// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        进度条: cc.Node,
        progress: cc.ProgressBar,

        //progress2: cc.ProgressBar, 用于尝试直接修改progress的
        //monsterPos: cc.Node,
    },

    onLoad() {

    },
    initOver() {
        cc.director.preloadScene("game");
        cc.director.loadScene("game");
    },
    start() {
        this.进度条.initw = this.进度条.width;
        this.进度条.width = 0;
        //this.progress2.progress = 0;
        this.allLoadNum = g_Res.getLoadAllNum();
        this.loadedNum = 0;
        this.progress.progress = 0;
        let proNode = this.progress.node;
        let lbproNode = proNode.getChildByName("lbPro");
        this.lbPro = lbproNode.getComponent(cc.Label);
        this.lbPro.string = "0%";
        g_Res.doLoad();
    },

    update() {
        this.loadedNum = g_Res.getLoadNum();
        if (this.进度条.width < this.进度条.initw * this.loadedNum / this.allLoadNum) {
            this.进度条.width += 5;
            this.lbPro.string = Math.floor(this.进度条.width / this.进度条.initw * 100) + '%';
        } else if (this.进度条.width >= this.进度条.initw) {
            this.initOver();
        }
        // this.loadedNum = g_Res.getLoadNum();
        // if (this.progress2.progress < this.loadedNum / this.allLoadNum) {
        //     this.progress2.progress += 0.02;
        //     //this.lbPro.string = Math.floor(this.进度条.width / this.进度条.initw * 100) + '%';
        // } //else if (this.进度条.width >= this.进度条.initw) {
        // //this.initOver();
        // //}

    },
});
